﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SW2A311A
{
    public class CondensingDryer : Dryer
    {
        #region Instansvariabler
        public bool WithHeatPump { get; protected set; }
        #endregion

        #region Constructors
        // CondensingDryer instantieres med indput parametre til alle fields og proporties, 
        // og sender dem videre til superklasserne Dryer og Product den ikke selv har fields til.
        public CondensingDryer(string name, double price, Dimensions dimension, double capacity,
            int dryTime, double energyConsumption, int noiseLevel, bool withHeatPump)
            : base(name, price, dimension, capacity, dryTime, energyConsumption, noiseLevel)
        {
            WithHeatPump = withHeatPump;
            EnergyClass = GetEnergyClass();
        }

        #endregion

        #region Metoder
        // Vi instantiere en Range-struct med min og max værdierne for hver energi-klasse hvorefter
        // vi med det samme kalder metoden DryerIsBetween() med den aktuelle værdi som indput parameter.
        // Range returnere true hvis indput parameteren lå mellem min og max ellers returneres false.
        public override EEnergyClass GetEnergyClass()
        {
            double energyCalc = EnergyConsumption / Capacity;

            if (new Range(0, 0.55).IsBetweenOrEqualMax(energyCalc))
                return EEnergyClass.A;
            else if (new Range(0.55, 0.64).IsBetweenOrEqualMax(energyCalc))
                return EEnergyClass.B;
            else if (new Range(0.64, 0.73).IsBetweenOrEqualMax(energyCalc))
                return EEnergyClass.C;
            else if (new Range(0.73, 0.82).IsBetweenOrEqualMax(energyCalc))
                return EEnergyClass.D;
            else if (new Range(0.82, 0.91).IsBetweenOrEqualMax(energyCalc))
                return EEnergyClass.E;
            else if (new Range(0.91, 1).IsBetweenOrEqualMax(energyCalc))
                return EEnergyClass.F;
            else
                return EEnergyClass.G;
        }

        public override string ToString() // ToString metode override der returnerer en string med alle fields og proporties fra CondensingDryer.
        {
            return string.Format("Type: Condensing Dryer \nManufacturer: {0}\nIncluding Heatpump: {1}\nCapacity: {2}L" +
                "\nEnergyconsumption: {3}\nEnergyclass: {4}\nDimensions: {5}\nPrice: {6:C}\n",
                Name, WithHeatPump ? "Yes" : "No", Capacity, EnergyConsumption, EnergyClass, Dimension, Price);
        }

        #region Equalsmetoder
        public override bool Equals(object obj)
        {
            CondensingDryer p = obj as CondensingDryer;

            if (this.GetType() != obj.GetType())
                return false;

            return base.Equals(obj) &&
                WithHeatPump == p.WithHeatPump;
        }

        public bool Equals(CondensingDryer p)
        {
            return base.Equals((Dryer)p) &&
                WithHeatPump == p.WithHeatPump;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode() ^
                WithHeatPump.GetHashCode();
        }
        #endregion
        #endregion
    }
}
